package com.dtsz.m2.ui.adapter;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.view.View;
import android.widget.Toast;

import com.dtsz.m2.R;
import com.dtsz.m2.refresh.baseadapter.CommonAdapter;
import com.dtsz.m2.refresh.baseadapter.ViewHolder;
import com.dtsz.m2.ui.model.Users;

import java.util.List;

public class InvitationNumberAdatper extends CommonAdapter<Users> {
    Context context;

    public InvitationNumberAdatper(Context context, List<Users> data, int layoutItemId) {
        super(context, layoutItemId, data);
        this.context = context;

    }

    @Override
    protected void convert(final ViewHolder holder, final Users users, int position) {
        holder.setText(R.id.tv_phone, users.getBuPhone());
        holder.getView(R.id.tv_phone).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String phone = users.getBuPhone();
                if (!"未绑定手机号码".equals(phone)) {
                    copy(context, users.getBuPhone());
                }
            }
        });
        String state = users.getBuMiningState();
        holder.setTextColor(R.id.tv_mining_state, "1".equals(state) ? context.getResources().getColor(R.color.colorMain) : context.getResources().getColor(R.color.colorFont5));
        holder.setText(R.id.tv_certification, "1".equals(users.getBuCertification()) ? "已实名" : "未实名");
    }

    //系统剪贴板-复制:   s为内容
    public void copy(Context context, String s) {
        // 获取系统剪贴板
        ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
        // 创建一个剪贴数据集，包含一个普通文本数据条目（需要复制的数据）
        ClipData clipData = ClipData.newPlainText(null, s);
        // 把数据集设置（复制）到剪贴板
        clipboard.setPrimaryClip(clipData);
        Toast.makeText(context, "复制成功", Toast.LENGTH_SHORT).show();
    }
}
